<!--文本输入框-->

<template>
  <div class="w-h-full" :style="{
    textAlign: 'center',
    lineHeight: $parent.$parent.layoutItem.layoutItemConfigData.height - 2 + 'px'
  }">
    <!--组件遮罩层，用于在设计器中显示-->
    <div v-if="shade" class="shade"></div>

    <Input ref="Input" v-model="value"
           :type="component.compConfigData.type"
           :size="component.compConfigData.size"
           :placeholder="component.compConfigData.placeholder"
           :clearable="component.compConfigData.clearable"
           :disabled="component.compConfigData.disabled"
           :readonly="component.compConfigData.readonly"
           :icon="component.compConfigData.icon"
           :prefix="component.compConfigData.prefix"
           :suffix="component.compConfigData.suffix"
           :search="component.compConfigData.search"
           :rows="component.compConfigData.rows"
           :style="Object.assign({
            width: component.compConfigData.inputStyle.width,
            transform: 'scale('+component.compConfigData.inputStyle.scaleValue+')'
           }, inputStyleObject)"
           @on-enter="onEnterHandler"
    />
  </div>
</template>

<script>

  import FuncCompMixin from '@/mixin/FuncCompMixin'
  import PnDesigner from '@/utils/PnDesigner'

  const _this = {
    name: 'InputComp', // 此名称必须填写，且必须与组件文件名相同
    mixins: [FuncCompMixin],
    attr: {
      version: '2.2',
      configDataTemp: Object.assign({

        type: 'text',
        size: 'large',
        placeholder: '请输入...',
        clearable: false,
        disabled: false,
        readonly: false,
        icon: '',
        prefix: '',
        suffix: '',
        search: false,
        rows: 2,
        defaultValue: '',

        inputStyle: {
          scaleValue: 1,
          width: '150px',
          backgroundColor: '#263238',
          color: '#fff',
          borderColor: '#2196f3'
        },

        onEnterCode: ''

      }, PnDesigner.buildFuncCompDatasourceField({ // 如果组件需要配置数据源，则需要调用此函数构建数据源字段对象
        ds_resultObjTemplate: [
          {
            field: 'value',
            remark: '内容'
          }
        ],
        ds_resultObj: [
          {
            "value": "我是组件内容"
          }
        ],
        ds_useFilter: false, // 是否使用过滤器，默认不使用
        ds_useTimer: false, // 是否开启定时器配置，默认不开启
      }), PnDesigner.buildFuncCompGlobalField(), PnDesigner.buildFuncCompInteractionConfiguration([
        PnDesigner.buildFuncCompInteractionStreamItem('itemEnter', [
          PnDesigner.buildFuncCompInteractionFieldsMapItem('value','')
        ])
      ]))
    },
    data() {
      return {
        value: ''
      }
    },
    mounted() {
      this.init();

      if (this.component.compConfigData.defaultValue) {
        this.value = this.component.compConfigData.defaultValue
      }
    },
    methods: {
      init () { // 组价初始化函数，函数名必须使用init，不可更改
        this.initDatasource(() => {
          this.runCustomGlobalJsCode()
        }, (result) => {
          this.runCustomGlobalJsCode()
        });
      },

      onEnterHandler () {
        let value = this.value;
        this.$PnDesigner.launchInteractionStream(this.component.compConfigData, 'itemEnter', {value: value})
        eval(this.component.compConfigData.onEnterCode)
      }
    },
    computed: {
      inputStyleObject () {
        return {
          '--background-color': this.component.compConfigData.inputStyle.backgroundColor,
          '--color': this.component.compConfigData.inputStyle.color,
          '--border-color': this.component.compConfigData.inputStyle.borderColor,
        }
      }
    }
  };

  export default _this
</script>

<style scoped>
  >>> .ivu-input {
    background-color: var(--background-color) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--color) !important;
  }
  >>> .ivu-input::-webkit-input-placeholder{
    color: var(--color) !important;
  }
  >>> .ivu-input::-moz-placeholder{
    color: var(--color) !important;
  }
  >>> .ivu-input-icon {
    color: var(--color) !important;
  }
  >>> .ivu-input-prefix i {
    color: var(--color) !important;
  }
  >>> .ivu-input-suffix i {
    color: var(--color) !important;
  }
</style>
